#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   get_version.py
@Time    :   2024/01/21 17:47:24
@Author  :   chakcy 
@Email   :   947105045@qq.com
@description   :   获取系统参数
'''

import winreg
import subprocess
import platform  

# 获取系统参数
def get_system_info() -> dict:
    return {
        'os_name': platform.system(),
        'os_version': platform.release(),
        'os_version_info': platform.version(),
        'machine': platform.machine()
    }

# 获取 windows 系统浏览器版本
def windows_chrome_version() -> str:
    try:   
        key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\Google\Chrome\BLBeacon')  
        version, _ = winreg.QueryValueEx(key, 'version')  
        return version  
    except WindowsError:  
        return "Windows 浏览器版本获取失败"

# 获取 Linux 系统浏览器版本
def linux_chrome_version() -> str:  
    try:  
        chrome_version = subprocess.check_output(['google-chrome', '--version']).decode('utf-8')   
        version_number = chrome_version.split()[-2]  
        return version_number  
    except subprocess.CalledProcessError:  
        return "Linux 浏览器版本获取失败"

# 获取浏览器版本
def get_chrome_version() -> dict:
    system_info = get_system_info()
    if system_info['os_name'] == 'Windows':
        return {"version": windows_chrome_version(), "os_name": "Windows"}
    elif system_info['os_name'] == 'Linux':
        return {"version": linux_chrome_version(), "os_name": "Linux"}
    else:
        return {"msg":"未知系统，无法获取浏览器版本", "os_name": system_info['os_name']}

# if __name__ == "__main__":
#     print(get_chrome_version())